package cn.codeinn.service1.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.codeinn.common.util.RS;
import cn.codeinn.service1.entity.Member;
import cn.vkits.core.date.DateUtil;
import cn.vkits.core.util.StrUtil;
import cn.vkits.crypto.SecureUtil;
import cn.vkits.http.HttpRequest;
import cn.vkits.http.HttpResponse;
import cn.vkits.json.JSONObject;
import cn.vkits.json.JSONUtil;

@RestController
@RequestMapping(value = "/utils")
public class UtilsController {

	@GetMapping(value = "/test")
	public RS testUtils() {

		// 1.JSONObject
		JSONObject obj = new JSONObject();
		obj.put("1", "2");

		String temp = "{\"a\":\"123\",\"b\":\"456\"}";
		JSONObject tempObj = JSONUtil.parseObj(temp);
		tempObj.getStr("a");

		Member member = new Member();
		member.setId(3);
		member.setUsername("XXB");
		String b = JSONUtil.toJsonStr(member);
		System.out.println(b);

		// 2.HttpRequest
		HttpResponse response = HttpRequest.post("url").header("name", "value").body("body").execute();
		if (response.isOk()) {
			String resStr = response.body();
			JSONObject res = JSONUtil.parseObj(resStr);
			System.out.println(res.getStr("code"));
		}
		// 3.StrUtil
		String str = "c";
		if (StrUtil.isNotBlank(str)) {

		}
		// 4. security
		SecureUtil.md5("aaa");

		// 5.date
		DateUtil.now();
		return RS.ok();
	}
}
